#include "recboxitem.h"
#include "ui_recboxitem.h"

RecBoxItem::RecBoxItem(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::RecBoxItem)
{
    ui->setupUi(this);
    ui->musicImageBox->installEventFilter(this);
}

RecBoxItem::~RecBoxItem()
{
    delete ui;
}

void RecBoxItem::setText(const QString &text)
{
    ui->recBoxItemText->setText(text);

}

void RecBoxItem::setImage(const QString &Imagepath)
{
    QString imgStyle = "background-repeat: no-repeat;background-image:url("+Imagepath+")";
    ui->recMusicImg->setStyleSheet(imgStyle);
}

bool RecBoxItem::eventFilter(QObject *object, QEvent *event)
{
    if(object==ui->musicImageBox)
    {
        if(event->type()==QEvent::Enter)
        {
           QPropertyAnimation* animation = new QPropertyAnimation(ui->musicImageBox, "geometry", this);
            animation->setDuration(100);
            animation->setStartValue(QRect(0, 20, ui->musicImageBox->width(), ui->musicImageBox->height()));
            animation->setEndValue( QRect(0, 0, ui->musicImageBox->width(), ui->musicImageBox->height()));
            animation->start();
            connect(animation,&QPropertyAnimation::finished,this,[=](){
                delete animation;
            });
        }
        else if(event->type()==QEvent::Leave)
        {
            QPropertyAnimation* animation = new QPropertyAnimation(ui->musicImageBox, "geometry", this);
            animation->setDuration(100);
            animation->setStartValue(QRect(0, 0, ui->musicImageBox->width(), ui->musicImageBox->height()));
            animation->setEndValue( QRect(0, 20, ui->musicImageBox->width(), ui->musicImageBox->height()));
            animation->start();
            connect(animation,&QPropertyAnimation::finished,this,[=](){
                delete animation;
            });
        }
    }
    return true;
}
